import { Component, OnInit,Input } from '@angular/core';
import {User} from "./User";
import {UserService} from "../user.service";
import { Router } from '@angular/router';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  user:User = new User();
  error:string;
  constructor(private userService:UserService,private router: Router) { }

  ngOnInit() {
    console.log('entry login')
    if (this.userService.isLogin()) {
      this.router.navigate(['/articles']);
    }
  }

  login() {
    this.userService.login(this.user, () => {
      console.log('登录成功')
      this.router.navigate(['/publish']);
    },() => {
      console.log('登录失败');
      this.error = 'error';
    });
    return false;
  }

}
